package com.bt.lms.ui.page.teaching.supervise;

import com.bt.lms.ui.page.sys.utils.MyHBox;
import com.bt.lms.ui.page.sys.utils.MyVBox;
import com.bt.lms.ui.page.teaching.supervise.action.PageAddCheckInCancelBtnAction;
import com.bt.lms.ui.page.teaching.supervise.action.InquireBtnAction;
import com.bt.lms.ui.vo.PageSkipInfo;
import javafx.collections.ObservableList;
import javafx.geometry.HPos;
import javafx.geometry.Insets;
import javafx.geometry.Pos;
import javafx.scene.Node;
import javafx.scene.control.Button;
import javafx.scene.control.DatePicker;
import javafx.scene.control.Label;
import javafx.scene.control.TextField;
import javafx.scene.layout.GridPane;
import javafx.scene.layout.VBox;

/**
 * 新增教师值机界面
 */
public class PageTeacherCheckInAdd extends VBox {

    /**
     * 界面跳转数据
     */
    private final PageSkipInfo pageSkipInfo;

    /**
     * 构建新增教师值机界面
     * @param pageSkipInfo 界面跳转数据
     */
    public PageTeacherCheckInAdd(PageSkipInfo pageSkipInfo) {

        //维护
        this.pageSkipInfo = pageSkipInfo;

        //大小
        int wight = 1280;
        this.setPrefWidth(wight);
        this.setPrefHeight(650);

        //布局
        Insets insets = new Insets(0);
        this.setPadding(insets);

        //组件
        //定位区域
        MyHBox locationHBox = new MyHBox();
        locationHBoxInit(locationHBox);
        this.getChildren().add(locationHBox);

        //输入区域
        MyVBox inputVBox = new MyVBox();
        inputVBoxInit(inputVBox);
        this.getChildren().add(inputVBox);

        //控制区域
        MyHBox controlHBox = new MyHBox();
        controlHBoxInit(controlHBox);
        this.getChildren().add(controlHBox);

    }

    /**
     * 输入区域初始化
     *
     * @param inputVBox 输入区域
     */
    private void inputVBoxInit(   MyVBox inputVBox) {

        //布局
        Insets insets = new Insets(12);
        inputVBox.setPadding(insets);
        inputVBox.setSpacing(8);
        inputVBox.setAlignment(Pos.CENTER_LEFT);

        //组件（位置）
        Label locationLab = new Label("新增值机安排");
        //组件添加
        ObservableList<Node> locationChildren = inputVBox.getChildren();
        locationChildren.add(locationLab);

        //组件（输入网格
        GridPane gridPane = inputGrid(inputVBox);
        inputVBox.getChildren().add(gridPane);
    }

    /**
     * 网格布局
     * @param myVBox 所在盒子
     * @return 网格布局
     */
    private    GridPane inputGrid(MyVBox myVBox) {

        //新建网格布局
        GridPane res = new GridPane();

        //大小
        res.setPrefWidth(1280);
        res.setPadding(new Insets(5));
        res.setHgap(10);//间隙（左右）
        res.setVgap(15);//间隙（上下）

        //日期控制 checkInDate
        Label checkInDateLab = new Label("值机日期：");
        DatePicker checkInDateDP = new DatePicker();
        res.add(checkInDateLab, 0, 1);
        res.add(checkInDateDP, 1, 1);
        GridPane.setHalignment(checkInDateLab, HPos.RIGHT);

        Label timeFrameLab = new Label("时段：");
        res.add(timeFrameLab,2,1);

        DatePicker beginDP = new DatePicker();
        res.add(beginDP,3,1);

        Label connectLab = new Label("至");
        res.add(connectLab,4,1);

        DatePicker finishDP = new DatePicker();
        res.add(finishDP,5,1);

        //时长 duration
        Label durationLab = new Label("时长：");
        TextField durationTF = new TextField();
        res.add(durationLab, 0, 2);
        res.add(durationTF, 1, 2);
        GridPane.setHalignment(durationLab, HPos.RIGHT);
        Label unit = new Label("分钟");
        res.add(unit, 2, 2);

        //值机教师 idType
        Label teacherLab = new Label("值机教师：");
        TextField teacherTF = new TextField();
        teacherTF.setId("teacherTF");
        res.add(teacherLab, 0, 3);
        res.add(teacherTF, 1, 3);
        GridPane.setHalignment(teacherLab, HPos.RIGHT);

        //检索教师列表
        Button inquireBtn = new Button("检索教师列表");
        res.add(inquireBtn,2,3);
        //事件
        InquireBtnAction inquireBtnAction = new InquireBtnAction(myVBox,2,pageSkipInfo);
        inquireBtn.setOnAction(inquireBtnAction);

        return res;
    }

    /**
     * 控制区域初始化
     *
     * @param controlHBox 控制区域
     */
    private void controlHBoxInit(   MyHBox controlHBox) {

        //布局
        Insets insets = new Insets(10);
        controlHBox.setPadding(insets);
        controlHBox.setSpacing(10);
        controlHBox.setAlignment(Pos.CENTER);

        //组件(确认)
        Button saveBtn = new Button("确认");
        //大小控制
        Insets saveBtnInsets = new Insets(10, 20, 10, 20);
        saveBtn.setPadding(saveBtnInsets);
        //组件添加
        ObservableList<Node> saveBtnChildren = controlHBox.getChildren();
        saveBtnChildren.add(saveBtn);

        //组件(取消)
        Button cancelBtn = new Button("取消");
        //大小控制
        Insets cancelBtnInsets = new Insets(10, 20, 10, 20);
        cancelBtn.setPadding(cancelBtnInsets);
        //事件
        PageAddCheckInCancelBtnAction pageAddCheckInCancelBtnAction = new PageAddCheckInCancelBtnAction(pageSkipInfo);
        cancelBtn.setOnAction(pageAddCheckInCancelBtnAction);
        //组件添加
        ObservableList<Node> cancelBtnChildren = controlHBox.getChildren();
        cancelBtnChildren.add(cancelBtn);

    }


    /**
     * 定位区域初始化
     *
     * @param locationHBox 定位区域容器
     */
    private void locationHBoxInit(   MyHBox locationHBox) {

        //控制数据
        int height = 42;

        //大小
        locationHBox.setPrefHeight(height);

        //布局
        Insets insets = new Insets(5);
        locationHBox.setPadding(insets);
        locationHBox.setSpacing(0);
        locationHBox.setAlignment(Pos.CENTER_LEFT);

        //组件
        Label siteLab = new Label("当前位置：");
        Label oneCatalogLab = new Label("🏠>系统管理");
        Label twoCatalogLab = new Label(">教师值机管理");
        Label threeCatalogLab = new Label(">新增值机安排");

        //添加组件
        locationHBox.getChildren().addAll(siteLab, oneCatalogLab, twoCatalogLab, threeCatalogLab);

    }
}
